<?php
/**
 * @Author: Xu Liu email:2867557054@qq.com
 * @Date:   2016-12-15 13:31:33
 * @Last Modified by:   Xu Liu
 * @Last Modified time: 2018-03-16 10:27:31
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
class plugin_jameson_read
{
    public function global_header()
    {
        global $_G;
        if ($_GET['mod'] == 'viewthread' && $_GET['tid'] && ($pid = DB::result_first('SELECT pid FROM %t WHERE tid=%d', array('jamesonread_colums', $_GET['tid'])))) {
            require_once libfile('function/jameson', 'plugin/jameson_read');
            $url = $_G['siteurl'].'plugin.php?id=jameson_read&act=read&tid='.$_GET['tid'].'&pid='.$pid;
            if(isset($_GET['highlight']) && $_GET['highlight']){
                $url .='&highlight='.$_GET['highlight'];
            }
            dheader('location:'.$url);
        }
    }
     function global_footer_output(){
        global $_G;
        // if($_GET['mod']=='space' && $_GET['do']=='thread' && $_GET['type']!='reply'){
        //     foreach ($GLOBALS['list'] as $key => $value) {
        //         if(C::t('#jameson_read#jamesonread_colums')->isColum($key)){
        //         }
        //     }
        //     return '';
        // }
    }
    
}

class plugin_jameson_read_forum extends plugin_jameson_read
{
    public function forumdisplay_top()
    {
        global $_G;
        require_once libfile('function/jameson', 'plugin/jameson_read');
        init_jameson();
        $books = array();
        $books = C::t('#jameson_read#jamesonread_books')->fetch_books_byfid($_G['fid']);
        if ($books) {
            include template('jameson_read:hook_bindbook');
            return $return;
        }
    }
}

class plugin_jameson_read_group extends plugin_jameson_read
{
    public function forumdisplay_top()
    {
        global $_G;
        require_once libfile('function/jameson', 'plugin/jameson_read');
        init_jameson();
        $books = array();
        $books = C::t('#jameson_read#jamesonread_books')->fetch_books_byfid($_GET['fid'],'qzfid');
        if ($books) {
            include template('jameson_read:hook_bindbook');
            return $return;
        }
    }
    public function group_top()
    {
        global $_G;
        require_once libfile('function/jameson', 'plugin/jameson_read');
        init_jameson();
        $books = array();
        $books = C::t('#jameson_read#jamesonread_books')->fetch_books_byfid($_GET['fid'],'qzfid');
        if ($books) {
            include template('jameson_read:hook_bindbook');
            return $return;
        }
    }
}

class plugin_jameson_read_home extends plugin_jameson_read
{
    // 用户个人空间 积分记录
    public function spacecp_credit_bottom()
    {
        global $_G;
        $jiangli = lang('plugin/jameson_read', 'fenxiangtiezijiangli');
        $gmtsfy  = lang('plugin/jameson_read', 'goumaitushufeiyong');
        $xstsfy  = lang('plugin/jameson_read', 'xiaoshoutushufeiyong');
        $dstsfy  = lang('plugin/jameson_read', 'dashangtushufeiyong');
        $bdstsfy = lang('plugin/jameson_read', 'beidashangtushufeiyong');
        $toupiao = lang('plugin/jameson_read', 'xiangzuozhetoupiao');
        $yongjin = lang('plugin/jameson_read', 'xiaoshouyongjin');
        $fatiejiangli = lang('plugin/jameson_read', 'fatiejiangli');
        $js      = <<<EOF
            <script>
                function jamesonreadhome(){
                    var alla = $("ct").getElementsByTagName('a');
                    for(var i=0,len=alla.length;i<len;i++){
                        var href = alla[i].getAttribute('href');
                        if(href.length>10){
                            if(/optype=jmd/.test(href)){
                                alla[i].setAttribute('href','javascript:;');
                                alla[i].innerHTML = '{$jiangli}';
                            }else if(/optype=jds/.test(href)){
                                alla[i].setAttribute('href','javascript:;');
                                alla[i].innerHTML = '{$dstsfy}';
                            }else if(/optype=jbd/.test(href)){
                                alla[i].setAttribute('href','javascript:;');
                                alla[i].innerHTML = '{$bdstsfy}';
                            }else if(/optype=jgm/.test(href)){
                                alla[i].setAttribute('href','javascript:;');
                                alla[i].innerHTML = '{$gmtsfy}';
                            }else if(/optype=jxs/.test(href)){
                                alla[i].setAttribute('href','javascript:;');
                                alla[i].innerHTML = '{$xstsfy}';
                            }else if(/optype=jtp/.test(href)){
                                alla[i].setAttribute('href','javascript:;');
                                alla[i].innerHTML = '{$toupiao}';
                            }else if(/optype=Y_J/.test(href)){
                                alla[i].setAttribute('href','javascript:;');
                                alla[i].innerHTML = '{$yongjin}';
                            }else if(/optype=FTJ/.test(href)){
                                alla[i].setAttribute('href','javascript:;');
                                alla[i].innerHTML = '{$fatiejiangli}';
                            }
                        }
                    }
                }
                _attachEvent(window,'load',jamesonreadhome);
            </script>
EOF;
        return $js;
    }
}